package com.abe.mvp.view.adapter;

import java.util.ArrayList;
import java.util.List;

import lecho.lib.hellocharts.view.ComboLineColumnChartView;
import android.annotation.SuppressLint;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.abe.mvp.model.bean.PatternBean;
import com.abe.threadmill.R;

@SuppressLint("InflateParams")
public class PatternCoverFlowAdapter extends BaseAdapter {

	private List<PatternBean> mData = new ArrayList<PatternBean>();
	private Context mContext;

	public PatternCoverFlowAdapter(Context context) {
		mContext = context;
	}

	public void setData(List<PatternBean> data) {
		mData = data;
	}

	@Override
	public int getCount() {
		return mData.size();
	}

	@Override
	public Object getItem(int pos) {
		return mData.get(pos);
	}

	@Override
	public long getItemId(int pos) {
		return pos;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {

		View rowView = convertView;

		if (rowView == null) {
			LayoutInflater inflater = (LayoutInflater) mContext
					.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			rowView = inflater.inflate(R.layout.item_list_motor_pattern, null);
			ViewHolder viewHolder = new ViewHolder();
			viewHolder.layout = (LinearLayout) rowView
					.findViewById(R.id.item_motor_pattern_layout);
			viewHolder.text = (TextView) rowView
					.findViewById(R.id.item_motor_pattern_name);
			viewHolder.chart = (ComboLineColumnChartView) rowView
					.findViewById(R.id.item_motor_pattern_chart);
			rowView.setTag(viewHolder);
		}

		ViewHolder holder = (ViewHolder) rowView.getTag();
		PatternBean bean = mData.get(position);
		holder.text.setText(bean.getName());
		holder.chart.setComboLineColumnChartData(bean.getData());
		return rowView;
	}

	static class ViewHolder {
		public LinearLayout layout;
		public TextView text;
		public ComboLineColumnChartView chart;
	}
}
